package com.example.photography.adapter.product;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.CollectsBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public abstract class CollectAdapter extends MyBaseAdapter {
    /**
     * 照片
     */
    private static final int PIC = 1;
    /**
     * 视频
     */
    private static final int VLO = 2;
    /**
     * 文章
     */
    private static final int ART = 3;
    //类型
    private int currentType = 0;

    public CollectAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder viewHolder = null;

        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_collect, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //根据位置得到数据
        CollectsBean.DataBean.CollectBean collectBean = (CollectsBean.DataBean.CollectBean) list.get(position);
        switch (collectBean.getType()) {
            case PIC:
                viewHolder.ivVlog.setVisibility(View.GONE);
                viewHolder.tvTag.setVisibility(View.GONE);
                break;
            case ART:
                viewHolder.ivVlog.setVisibility(View.GONE);
                break;
            case VLO:
                viewHolder.tvTag.setVisibility(View.GONE);
        }
        viewHolder.svCover.setImageURI(Uri.parse(collectBean.getCover()));
        viewHolder.tvTitle.setText("" + collectBean.getTitle());
        viewHolder.tvCollectNum.setText("" + collectBean.getCollect_num());
        viewHolder.svHead.setImageURI(Uri.parse(collectBean.getUser_head()));
        viewHolder.tvName.setText(collectBean.getUser_name());

        viewHolder.itemCollect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setItemListen(collectBean.getCollect_id());
            }
        });
        return convertView;
    }


    public abstract void setItemListen(int id);


    static
    class ViewHolder {
        @BindView(R.id.sv_cover)
        SimpleDraweeView svCover;
        @BindView(R.id.tv_tag)
        TextView tvTag;
        @BindView(R.id.iv_vlog)
        ImageView ivVlog;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.sv_head)
        SimpleDraweeView svHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_collect_num)
        TextView tvCollectNum;
        @BindView(R.id.item_collect)
        LinearLayout itemCollect;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
